home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_8 / issue_06 / risc_os / Fonts / Methods < prev   
Encoding:
Text File  |  1988-12-07  |  8.8 KB  |  213 lines

  1. > Fonts.Methods
  2.  
  3. Summary
  4. -------
  5.  
  6.         Font$Path and Font$Prefix
  7.         summary of font files
  8.         rules for cacheing
  9.         Font_MakeBitmap
  10.  
  11. Font$Path and Font$Prefix
  12. -------------------------
  13.  
  14. The old font manager allowed access to a single directory of fonts, whose
  15. name was held in the variable Font$Prefix.  All calls to Font_FindFont went
  16. through this variable, and also Font_ListFonts (or *FontCat).
  17.  
  18. The new font manager gets its fonts via Font$Path, rather than Font$Prefix,
  19. allowing separate libraries of fonts to be added to the system.  When
  20. Font_FindFont is called, the font manager looks up the name via Font$Path,
  21. using the first directory it finds which has the correct name, as long as it
  22. contains an IntMetrics file.
  23.  
  24. For compatibility, the Font Manager on initialisation looks to see if
  25. Font$Path is already defined - if not, it initialises it as follows:
  26.  
  27.         *SetMacro Font$Path <Font$Prefix>.
  28.  
  29. Note the "." on the end - this is required because Font$Path is a path,
  30. whereas Font$Prefix was just a directory name, rather than a prefix.
  31.  
  32. Font_ListFonts and *FontCat now accept an optional path string rather than a
  33. directory name, for example:
  34.  
  35.         *FontCat                      ; uses <Font$Path>
  36.         *FontCat adfs:$.Fonts.,net:   ; each path element is a prefix
  37.  
  38. If more than one occurrence of the same font is discovered, only the first
  39. one will be reported.  This allows an application calling Font_ListFonts to
  40. be sure that all font names reported are unique.
  41.  
  42.  
  43. Summary of Font Files
  44. ---------------------
  45.  
  46. The font files relating to a font are all contained in a single directory:
  47.  
  48.         IntMetrics              ; metrics information (character widths etc)
  49.         x90y45                  ; old format pixel file (4-bpp)
  50.         f9999x9999              ; new format pixel file (4-bpp)
  51.         b9999x9999              ; new format pixel file (1-bpp)
  52.         Outlines                ; new format outline file
  53.  
  54. Note that the '9999's referred to above mean 'any decimal number in the
  55. range 1..9999'.  They refer to the pixel size of the font contained within
  56. the file, which is equal to:
  57.  
  58.         (font size in 1/16ths of a point) * dots per inch / 72
  59.  
  60. so, for example, a file containing 4-bpp 12 point text at 90 dots per inch
  61. would be called f240x240, because 12*16*90/72 = 240.
  62.  
  63. The minimal requirement for a font is that it should contain an IntMetrics
  64. file and an x90y45 or Outlines file.  In addition, it can have any number of
  65. f9999x9999 or b9999x9999 files, to speed up the cacheing of common sizes.
  66.  
  67.  
  68. Rules for cacheing
  69. ------------------
  70.  
  71. Where several font files exist in the same directory, the Font Manager must
  72. decide which file is most suitable as the data source for a particular font
  73. in a particular size and number of colours.
  74.  
  75. The number of colours to be used is determined by the 'font colour offset'
  76. supplied in the Font_SetFontColours call:
  77.  
  78.         SWI Font_SetFontColours:
  79.         R0 = font handle (0 ==> no change)
  80.         R1 = background colour
  81.         R2 = first foreground colour
  82.         R3 = font colour offset
  83.  
  84. Here the font foreground colour is given by R2+R3, with R3 intermediate
  85. shades being used to provide anti-aliasing.  If R3 is zero, the font is
  86. being painted in monochrome.  When painting, the same font handle can be
  87. used for monochrome as for anti-aliased text, but the font manager may have
  88. different sets of data in its cache for the two cases.
  89.  
  90. In addition to the number of colours being used, the font manager also takes
  91. note of various 'user thresholds' which can be configured in CMOS RAM to
  92. reflect the preferences of the user.  These determine the maximum font size
  93. for which a particular action will be taken: for example, you can set a font
  94. size threshold above which no anti-aliasing will be performed, even if
  95. Font_SetFontColours indicates otherwise.
  96.  
  97. The various thresholds are set up as follows:
  98.  
  99.         *Configure FontSize <n>k  ; min size of cache
  100.         *Configure FontMax  <n>k  ; max size of 'auto-grow' cache
  101.         *Configure FontMax1 <h>   ; max size of non-exact font from x90y45
  102.         *Configure FontMax2 <h>   ; max size of anti-aliased outlines
  103.         *Configure FontMax3 <h>   ; max size of cached outlines
  104.         *Configure FontMax4 <w>   ; max size of horizontally-subpixeled font
  105.         *Configure FontMax5 <h>   ; max size of vertically-subpixeled font
  106.  
  107. where <h> refers to the maximum font pixel height (pixel height = point
  108. height * dpi / 72), and <w> to the maximum font pixel width.
  109.  
  110. FontSize / FontMax
  111. ------------------
  112.  
  113. FontSize refers to the initial cache size, which is asserted when the font
  114. manager is initialised or *RMReInit'ed.  The minimum cache size can also be
  115. changed from the Task Manager, by dragging the font cache bar directly,
  116. although this is not remembered when the font manager is re-initialised.
  117.  
  118. If FontMax is bigger than the minimum font size, the font manager will
  119. attempt to expand the cache if it cannot obtain enough cache memory by
  120. throwing away unused blocks (ie. ones that belong to fonts which have had
  121. Font_FindFont called on them more often than Font_LoseFont).  Once the cache
  122. has expanded up to FontMax, the font manager will throw away the oldest
  123. block found, even if it is in use. This can result in the font manager
  124. 'thrashing', since during a window redraw it is possible that all fonts will
  125. have to be thrown away and recached in turn.
  126.  
  127. FontMax1
  128. --------
  129.  
  130. If a font has both an x90y45 file and an Outlines file, the font manager is
  131. in something of a quandary.  It would rather use the outlines file in all
  132. cases, since it always produces results at least as good as the scaled
  133. bitmaps, but unfortunately it does take longer.
  134.  
  135. The solution is that the font manager will use the x90y45 version of a font
  136. either if the exact size required is contained in the file, or if the font
  137. size required is less than or equal to the value specified in FontMax1.
  138.  
  139. Note that the f9999x9999 (or b9999x9999, as appropriate) will always be
  140. preferred if the exact size is found, and it is also possible to scale from
  141. an f9999x9999 file, by creating an x90y45 file which contains only the name
  142. of the f9999x9999 file (#### - not yet implemented).  In the latter case,
  143. the same rules apply concerning FontMax1, if there is also an Outlines file.
  144.  
  145. FontMax2
  146. --------
  147.  
  148. If the font size required is larger than this value, then the font manager
  149. will never convert from outlines to 4-bpp bitmaps (it will use 1-bpp
  150. instead).  It will use an f9999x9999 or x90y45 version of the font if the
  151. exact size is found or the font size is less than or equal to FontMax1.
  152.  
  153. FontMax3
  154. --------
  155.  
  156. If the font size required is larger than this value, the font manager will
  157. not store the results of converting from outlines to bitmaps, but will
  158. instead draw the data directly onto the destination, cacheing the outlines
  159. themselves instead.  Note that in this case the text is not drawn
  160. anti-aliased, since the Draw module is used to draw the outlines directly.
  161.  
  162. NB: The font manager sets up the appropriate GCOL and TINT settings when
  163.     drawing the outlines, but it resets them afterwards.
  164.  
  165. FontMax4
  166. --------
  167.  
  168. If the font width is less than or equal to FontMax4, the font manager will
  169. try to use the outlines file rather than x90y45, and will construct 4
  170. bitmaps for each character, corresponding to 4 possible subpixel positions
  171. on the screen.  When painting the text, it will use the bitmap which
  172. corresponds most closely to the required horizontal subpixel position.
  173.  
  174. Note that if there is an f9999x9999 file of the appropriate size, this will
  175. take precedence over the settings of FontMax4 and FontMax5.  This bitmap may
  176. however have been constructed with subpixel positioning already performed
  177. (see Font_MakeBitmap).
  178.  
  179. FontMax5
  180. --------
  181.  
  182. This is similar to FontMax4 except that the font height determines whether
  183. it is performed, and it constructs bitmaps for each of 4 possible vertical
  184. subpixel alignments.
  185.  
  186. Note that if both horizontal and vertical subpixeling are performed, there
  187. will be 16 bitmaps for each character.
  188.  
  189.  
  190. Font_MakeBitmap
  191. ---------------
  192.  
  193.         SWI Font_MakeBitmap
  194.         R1 = font handle, or
  195.              R1 -> font name
  196.              R2,R3 = x/y point size * 16
  197.              R4,R5 = x/y dpi (or 0,0 for default)
  198.         R6 = flag word:
  199.              bit 0 set => construct f9999x9999 (else b9999x9999)
  200.              bit 1 set => do horizontal subpixel positioning
  201.              bit 2 set => do vertical subpixel positioning
  202.              bits 3..31 reserved (must be 0)
  203.  
  204. This call allows a particular size of a font to be pre-stored in the font's
  205. directory so that it can be cached more quickly.  It is especially useful if
  206. subpixel positioning is to be performed, since this takes a long time if
  207. done directly from outlines.
  208.  
  209. #### Currently this call only works properly if:
  210.      (a) the font has an outlines file
  211.      (b) the font does not already have the required bitmap file
  212.          (in this case it all goes horribly wrong!)
  213.